package com.ycb.controller;

import com.ycb.entity.User;
import com.ycb.feign.UserClient;
import com.ycb.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 黄泽群
 * @since 2023-12-11
 */
@RestController
@RequestMapping("/")
@RequiredArgsConstructor
public class UserController implements UserClient {

    private final UserService userService;

    @Override
    public User subAmount(Integer userId, Integer subAmt) {
        User user = userService.getById(userId);
        if (user.getAmt() < subAmt){
            throw new RuntimeException("用户余额不足");
        }
        user.setAmt(user.getAmt() - subAmt);
        userService.updateById(user);
        return user;
    }
}
